﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide.ui {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import L10n.*;
    import com.zynga.skelly.util.*;

    public class NewGuiderDialog extends WelcomeDialog {

        private const PIC_WIDTH:uint = 50;
        private const PIC_HEIGHT:uint = 50;

        private var m_photoPanel:JPanel;
        private var m_textAP:AssetPane;

        public function NewGuiderDialog(_arg1:String, _arg2:String="", _arg3:int=0, _arg4:Function=null, _arg5:Boolean=true, _arg6:String="", _arg7:String="", _arg8:Function=null){
            super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8);
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            var _local7:AssetPane;
            var _local2:Object = m_loaderObj;
            m_advisor = m_avatarContent;
            m_speech = (new _local2.speechBubbleLeft() as DisplayObject);
            m_jpanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            this.m_photoPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 2, true));
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            _local3.setBackgroundDecorator(new MarginBackground(m_speech, new Insets(0, 0, 10, 0)));
            var _local5 = 290;
            if (m_dialogTitle){
                _local7 = ASwingHelper.makeMultilineCapsText(m_dialogTitle, _local5, EmbeddedArt.TITLE_FONT, TextFormatAlign.LEFT, 16, EmbeddedArt.darkBlueTextColor, null, true);
                _local4.append(_local7);
            };
            this.m_textAP = ASwingHelper.makeMultilineText(ZLoc.t("Tutorials", "NewGuiderWelcome"), _local5, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 16, EmbeddedArt.brownTextColor, null, true);
            this.m_textAP.setPreferredHeight(60);
            _local4.appendAll(this.m_photoPanel, this.m_textAP, ASwingHelper.verticalStrut(10));
            ASwingHelper.prepare(this.m_photoPanel);
            _local4.setBorder(new EmptyBorder(null, new Insets(10, 50, 0, 25)));
            var _local6:JPanel = this.createButtonPanel();
            _local4.append(_local6);
            _local3.append(_local4);
            ASwingHelper.prepare(_local3);
            m_jpanel.append(_local3);
            finalizeAndShow();
            Global.world.addEventListener(FarmGameWorldEvent.USER_CHANGED, this.onFriendBarLoaded);
            this.loadFriendImage();
        }
        private function onFriendBarLoaded(_arg1:FarmGameWorldEvent=null):void{
            Global.world.removeEventListener(FarmGameWorldEvent.USER_CHANGED, this.onFriendBarLoaded);
            this.loadFriendImage();
        }
        private function loadFriendImage():void{
            var _local4:Friend;
            var _local5:JPanel;
            var _local6:AssetPane;
            var _local7:String;
            if (Global.friendbar == null){
                return;
            };
            var _local1:uint;
            var _local2:Array = Global.friendbar.concat();
            _local2 = _local2.sortOn("xp", (Array.DESCENDING | Array.NUMERIC));
            var _local3:uint;
            while (_local3 < _local2.length) {
                _local4 = (_local2[_local3] as Friend);
                if (((_local4.fake) || ((_local4.m_uid == Global.getPlayer().uid)))){
                } else {
                    if (_local1 < 5){
                        _local5 = this.createPhotoPane(_local4.m_profilePic);
                        this.m_photoPanel.append(_local5);
                        _local6 = ASwingHelper.makeMultilineText(_local4.m_name, 52, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 16, EmbeddedArt.brownTextColor, null, true);
                        LocaleHelper.localSetting.TextField_adjust((_local6.getAsset() as TextField), {
                            embedFonts:false,
                            font:EmbeddedArt.SYSTEM_FONT
                        });
                        _local5.append(_local6);
                        ASwingHelper.prepare(this.m_photoPanel);
                    };
                    _local1++;
                };
                _local3++;
            };
            if (_local1 > 0){
                _local7 = ZLoc.t("Tutorials", "NewGuiderWelcome");
                if (_local1 > 5){
                    _local7 = (ZLoc.t("Tutorials", "NewGuiderWelcome_friendsNum", {num:(_local1 - 5)}) + _local7);
                };
                (this.m_textAP.getAsset() as TextField).text = _local7;
                this.m_textAP.dispatchEvent(new UIEvent(UIEvent.REFRESH_DIALOG, "textChanged", true));
            };
        }
        protected function createPhotoPane(_arg1:String):JPanel{
            var iconPane:* = null;
            var iconLoader:* = null;
            var phoUrl:* = _arg1;
            iconPane = new AssetPane();
            iconLoader = LoadingManager.load(phoUrl, Curry.curry(function (_arg1:JPanel, _arg2:Event):void{
                iconPane.setAsset(iconLoader);
                ASwingHelper.prepare(_arg1);
                iconPane.setPreferredSize(new IntDimension(PIC_WIDTH, PIC_HEIGHT));
                iconPane.setMinimumSize(new IntDimension(PIC_WIDTH, PIC_HEIGHT));
                iconPane.setMaximumSize(new IntDimension(PIC_WIDTH, PIC_HEIGHT));
                _arg1.dispatchEvent(new UIEvent(UIEvent.REFRESH_DIALOG, "iconLoaded", true));
            }, this.m_photoPanel));
            var iconInnerPane:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            iconInnerPane.append(iconPane);
            return (iconInnerPane);
        }
        override protected function createButtonPanel():JPanel{
            m_button = new CustomButton(ZLoc.t("Tutorials", "NewGuiderButton"), null, "GreenButtonUI");
            m_button.addActionListener(onPanelClick, 0, true);
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local1.append(m_button);
            return (_local1);
        }

    }
}//package Modules.guide.ui 
